package com.uzai.console.web.wechatprivate;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.uzai.common.enums.DeviceTypeEnum;
import com.uzai.console.annotation.SystemLogType;
import com.uzai.console.common.utils.Tools;
import com.uzai.console.dto.device.DeviceQuery;
import com.uzai.console.dto.wechatprivate.wxq.wxgroup.*;
import com.uzai.console.dto.wechatwork.wxq.wxgroup.BatchAddManagerDto;
import com.uzai.console.enums.OperationTypeEnum;
import com.uzai.console.enums.SystemModelEnum;
import com.uzai.console.service.device.DeviceService;
import com.uzai.console.service.wechatprivate.WxGroupService;
import com.uzai.console.service.wechatprivate.WxGroupSyncService;
import com.uzai.console.vo.device.DeviceInfoVo;
import com.uzai.console.vo.wechatprivate.wxq.wxgroup.WxGroupInfoVo;
import com.uzai.console.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 微信群
 * @author liuqi
 * @date 2021年08月16日 15:11
 */
@Api(value = "个人微信微信群", tags = "个人微信|微信群")
@ApiSort(5)
@RestController
public class WxGroupController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(WxGroupController.class);

    @Autowired
    private WxGroupService wxGroupService;
    @Autowired
    private DeviceService deviceService;
    @Autowired
    private WxGroupSyncService wxGroupSyncService;

    @ApiOperation(value = "查询微信群列表", notes = "查询微信群列表", response = WxGroupInfoVo.class)
    @ApiOperationSupport(order = 1)
    @PostMapping("/wxGroup/findWxGroupList")
    public Object findWxGroupList(@RequestBody WxGroupQuery wxGroupQuery){
        wxGroupQuery.setUserType(1);//查询微信群
        return wxGroupService.findWxGroupList(wxGroupQuery);
    }

    @ApiOperation(value = "查询个人微信微信群详情", response = WxGroupInfoVo.class)
    @ApiOperationSupport(order = 2)
    @PostMapping("/wxGroup/findWxGroupInfo")
    public Object findWxGroupInfo(@RequestBody WxGroupIdDto wxGroupIdDto) {
        return wxGroupService.findWxGroupInfo(wxGroupIdDto);
    }

    @SystemLogType(model = SystemModelEnum.DeviceWechatWxGroup, type = OperationTypeEnum.QUIT)
    @ApiOperation(value = "退出微信群", notes = "退出微信群")
    @ApiOperationSupport(order = 2)
    @PostMapping("/wxGroup/quitWxGroup")
    public Object quitWxGroup(@RequestBody WxGroupIdDto wxGroupIdDto){
        wxGroupService.quitWxGroup(wxGroupIdDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.DeviceWechatWxGroup, type = OperationTypeEnum.QUIT)
    @ApiOperation(value = "批量退出微信群", notes = "批量退出微信群")
    @ApiOperationSupport(order = 2)
    @PostMapping("/wxGroup/quitWxGroupBatch")
    public Object quitWxGroupBatch(@RequestBody WxGroupIdListDto wxGroupIdListDto){
        wxGroupSyncService.quitWxGroupBatch(wxGroupIdListDto);
        return true;
    }

    @ApiOperation(value = "查询机器人列表", notes = "查询机器人列表", response = DeviceInfoVo.class)
    @ApiOperationSupport(order = 3)
    @PostMapping("/wxGroup/findDeviceList")
    public Object findDeviceList(){
        DeviceQuery deviceQuery = new DeviceQuery();
        deviceQuery.setDeviceType(DeviceTypeEnum.DT_PC_WECHAT.getKey());
        deviceQuery.setMerId(getLoginInfo().getMerId());
        return deviceService.findDeviceList(deviceQuery);
    }

    @SystemLogType(model = SystemModelEnum.DeviceWechatWxGroup, type = OperationTypeEnum.SENDMESSAGE)
    @ApiOperation(value = "发送消息", notes = "发送消息")
    @ApiOperationSupport(order = 4)
    @PostMapping("/wxGroup/sendMessage")
    public Object sendMessage(@RequestBody WxGroupSendMessageDto wxGroupSendMessageDto){
        wxGroupService.sendMessage(wxGroupSendMessageDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.DeviceWechatWxGroup, type = OperationTypeEnum.SENDMESSAGE)
    @ApiOperation(value = "批量发送消息", notes = "批量发送消息")
    @ApiOperationSupport(order = 4)
    @PostMapping("/wxGroup/sendMessageBatch")
    public Object sendMessage(@RequestBody WxGroupSendMessageBatchDto wxGroupSendMessageBatchDto){
        wxGroupSyncService.sendMessageBatch(wxGroupSendMessageBatchDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.DeviceWechatWxGroup, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "修改管理方案（弃用）", notes = "修改管理方案（弃用）")
    @ApiOperationSupport(order = 5)
    @PostMapping("/wxGroup/updateManagePlan")
    public Object updateManagePlan(@RequestBody WxGroupUpdateManagePlanDto wxGroupUpdateManagePlanDto){
        wxGroupService.updateManagePlan(wxGroupUpdateManagePlanDto);
        try {
            Thread.sleep(1000);
        }catch (Exception e){

        }
        return true;
    }

    @SystemLogType(model = SystemModelEnum.DeviceWechatWxGroup, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "批量修改管理方案", notes = "批量修改管理方案")
    @ApiOperationSupport(order = 5)
    @PostMapping("/wxGroup/batchUpdateManagePlan")
    public Object batchUpdateManagePlan(@RequestBody WxGroupBatchUpdateManagePlanDto wxGroupBatchUpdateManagePlanDto){
        wxGroupService.batchUpdateManagePlan(wxGroupBatchUpdateManagePlanDto);
        try {
            Thread.sleep(1000);
        }catch (Exception e){

        }
        return true;
    }

    @ApiOperation(value = "查询已经配置了管理方案的微信群列表", notes = "查询已经配置了管理方案的微信群列表", response = WxGroupInfoVo.class)
    @ApiOperationSupport(order = 8)
    @PostMapping("/wxGroup/findWxqGroupManagePlanList")
    public Object findWxqGroupManagePlanList(@RequestBody WxGroupQuery wxGroupQuery){
        //return wxGroupService.findWxqGroupManagePlanList(wxqGroupManagePlanQuery);
        wxGroupQuery.setUserType(1);//查询微信群
        wxGroupQuery.setManagePlanIdFlag(1);//开启过滤未配置管理方案
        //如果开启了wxid过滤
        if(Tools.getInteger(wxGroupQuery.getWxidDistinctFlag()).intValue() == 1){
            wxGroupQuery.setManagePlanIdFlag(null);//开启过滤未配置管理方案
        }

        return wxGroupService.findWxGroupList(wxGroupQuery);
    }

    @ApiOperation(value = "个人微信群刷新群成员", notes = "个人微信群刷新群成员")
    @ApiOperationSupport(order = 6)
    @PostMapping("/wxGroup/refreshGroupMember")
    public Object refreshGroupMember(@RequestBody WxGroupIdDto wxGroupIdDto){
        wxGroupService.refreshGroupMember(wxGroupIdDto);
        return true;
    }

    @ApiOperation(value = "个人微信群批量刷新群成员", notes = "个人微信群批量刷新群成员")
    @ApiOperationSupport(order = 7)
    @PostMapping("/wxGroup/refreshGroupMemberBatch")
    public Object refreshGroupMemberBatch(@RequestBody WxGroupIdListDto wxGroupIdListDto){
        wxGroupSyncService.refreshGroupMemberBatch(wxGroupIdListDto);
        return true;
    }

    @ApiOperation(value = "个人微信群修改群昵称", notes = "个人微信群修改群昵称")
    @ApiOperationSupport(order = 9)
    @PostMapping("/wxGroup/nickName/update")
    public Object updateWxWorkGroupNickName(@RequestBody WxGroupUpdateNicknameDto wxGroupUpdateNicknameDto){
        wxGroupService.updateWxGroupNickName(wxGroupUpdateNicknameDto);
        return true;
    }

    @ApiOperation(value = "个人微信群创建群", notes = "个人微信群创建群")
    @ApiOperationSupport(order = 10)
    @PostMapping("/wxGroup/create")
    public Object createWxWorkGroup(@RequestBody WxGroupCreateDto wxGroupCreateDto){
        wxGroupService.createWxGroup(wxGroupCreateDto);
        return true;
    }

    @ApiOperation(value = "个人微信群邀请进群", notes = "个人微信群邀请进群")
    @ApiOperationSupport(order = 11)
    @PostMapping("/wxGroup/invite")
    public Object inviteWxWorkGroup(@RequestBody WxGroupInviteDto wxGroupInviteDto){
        wxGroupService.inviteWxGroup(wxGroupInviteDto);
        return true;
    }

    @ApiOperation(value = "个人微信群批量邀请进群", notes = "个人微信群批量邀请进群")
    @ApiOperationSupport(order = 11)
    @PostMapping("/wxGroup/batchInvite")
    public Object batchInviteWxGroup(@RequestBody WxGroupBatchInviteDto wxGroupBatchInviteDto){
        wxGroupService.batchInviteWxGroup(wxGroupBatchInviteDto);
        return true;
    }

    @ApiOperation(value = "个人微信群发送群公告", notes = "个人微信群发送群公告")
    @ApiOperationSupport(order = 14)
    @PostMapping("/wxGroup/notice/send")
    public Object sendnotice(@RequestBody WxGroupSendNoticeDto wxGroupSendNoticeDto){
        wxGroupService.sendNotice(wxGroupSendNoticeDto);
        return true;
    }

    @ApiOperation(value = "个人微信群批量发送群公告", notes = "个人微信群批量发送群公告")
    @ApiOperationSupport(order = 14)
    @PostMapping("/wxGroup/notice/batchSend")
    public Object batchSendNotice(@RequestBody WxGroupBatchSendNoticeDto wxGroupBatchSendNoticeDto){
        wxGroupService.batchSendNotice(wxGroupBatchSendNoticeDto);
        return true;
    }

    @ApiOperation(value = "个人微信群刷新群成员", notes = "个人微信群刷新群成员")
    @ApiOperationSupport(order = 15)
    @PostMapping("/wxGroup/refreshMember")
    public Object refreshMember(@RequestBody WxGroupIdDto wxGroupIdDto){
        wxGroupService.refreshMember(wxGroupIdDto);
        return true;
    }

    @ApiOperation(value = "个人微信群批量踢出群成员", notes = "个人微信群批量踢出群成员")
    @ApiOperationSupport(order = 16)
    @PostMapping("/wxGroup/batchKickWxGroupMember")
    public Object batchKickWxGroupMember(@RequestBody BatchKickWxGroupMemberDto batchKickWxGroupMemberDto){
        wxGroupService.batchKickWxGroupMember(batchKickWxGroupMemberDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.DeviceWechatWxGroup, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "修改个人微信群备注", notes = "修改个人微信群备注")
    @ApiOperationSupport(order = 17)
    @PostMapping("/wxGroup/updateRemark")
    public Object updateRemark(@RequestBody WxGroupUpdateRemarkDto wxGroupUpdateRemarkDto){
        wxGroupService.updateRemark(wxGroupUpdateRemarkDto);
        return true;
    }

    @ApiOperation(value = "个人微信批量添加群管理员", notes = "个人微信批量添加群管理员")
    @ApiOperationSupport(order = 18)
    @PostMapping("/wxGroup/batchAddManager")
    public Object batchAddManager(@RequestBody BatchAddManagerDto batchAddManagerDto){
        wxGroupService.batchAddManager(batchAddManagerDto);
        return true;
    }

}
